package com.tencent.sr.iris.basic.mp.restapi.controller.station;

import com.tencent.sr.iris.basic.mp.service.station.StationMessageService;
import com.tencent.sr.iris.basic.service.interfaces.request.station.StationMessageRecordBasicRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.station.StationMessageRecordPageRequest;
import com.tencent.sr.iris.basic.service.interfaces.response.station.StationMessagePageResponse;
import com.tencent.sr.iris.basic.service.interfaces.response.station.StationMessageRecordPageResponse;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api("C端-站内信")
@RequestMapping("/iris/basic/mp/v1/message/record")
public class StationMessageRecordController {
    @Resource
    private StationMessageService stationMessageService;
    @Resource
    private AppUser appUser;

    @ApiOperation("查询用户未读站内信消息数量")
    @PostMapping("/unreadNum")
    HttpResult<Long> unreadNum(@Valid @RequestBody StationMessageRecordBasicRequest request) {
        request.setUid(appUser.getUid());
        return HttpResult.succ(stationMessageService.unreadNum(request));
    }

    @ApiOperation("站内信频道消息统计和列表")
    @PostMapping("/channelAndStationPage")
    HttpResult<List<StationMessageRecordPageResponse>> channelAndStationPage(
            @Valid @RequestBody StationMessageRecordPageRequest request) {
        request.setUid(appUser.getUid());
        return HttpResult.succ(stationMessageService.channelAndStationPage(request));
    }

    @ApiOperation("小程序站内信单个频道分页查询")
    @PostMapping("/page")
    HttpResult<PaginationResponse<StationMessagePageResponse>> page(
            @Valid @RequestBody PaginationRequest<StationMessageRecordBasicRequest> request) {
        request.getQueryCriteria().setUid(appUser.getUid());
        return HttpResult.succ(stationMessageService.page(request));
    }

    @ApiOperation("标记站内信已读")
    @PostMapping("/readRecord")
    HttpResult<Boolean> readRecord(@Valid @RequestBody StationMessageRecordBasicRequest request) {
        request.setUid(appUser.getUid());
        return HttpResult.succ(stationMessageService.readRecord(request));
    }

}
